//
//  RequiredTitleView.swift
//  GreenDeal
//
//  Created by Moennig Q on 30/12/2022.
//

import UIKit

class TitleLabelWithRequired: UIView {
    let titleLabel = BaseLabel()
    let isRequiredImageViewSize: CGFloat = 7
    static var titleLefitMargin: CGFloat {//7是isRequiredImageViewSize
        return 7 + 2
    }
    //IB init
    required init?(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
    }
    //纯代码创建
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    init(_ title: String) {
        super.init(frame: CGRect.zero)
        self.setUpView(title)
    }
    private func setUpView(_ title: String) {
        let isRequiredImageView = UIImageView(image: UIImage(named: "checkListCellStar"))
        
        
        //label
        titleLabel.text = title
        titleLabel.textColor = UIColor(hexStr: Constant.RequiredTitleColorHexStr)
        titleLabel.setFont(R.font.interMedium(size: 14))
        titleLabel.numberOfLines = 0
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(TitleLabelWithRequired.titleLefitMargin)
            make.top.bottom.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        //isRequiredImageView
        self.addSubview(isRequiredImageView)
        isRequiredImageView.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.width.height.equalTo(isRequiredImageViewSize)
            make.top.equalTo(titleLabel).offset(4)
        }
    }
    

}
